<template>
  <el-dialog class="do-dialog" @opened="$store.commit('dialogTop')" title="编辑" :visible.sync="visible" @close="dialogClose()">
    <el-form :model="model" :rules="rules" ref="iForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="企业名称" prop="enterpriseName" :rules="[{ 'required':true, 'message': '请输入企业名称','trigger': 'blur'}]">
        <el-input clearable size="mini" v-model="model.enterpriseName" type="text" auto-complete="off" placeholder="企业名称"></el-input>
      </el-form-item>
      <el-form-item label="企业简称" prop="enterpriseAlias" :rules="[{ 'required':true, 'message': '请输入企业简称','trigger': 'blur'}]">
        <el-input clearable size="mini" v-model="model.enterpriseAlias" type="text" auto-complete="off" placeholder="企业简称"></el-input>
      </el-form-item>      
      <el-form-item label="企业配额" prop="vehicleQuota" :rules="[{ 'required':true, 'message': '请输入企业配额','trigger': 'blur'}]">
        <el-input clearable size="mini" v-model="model.vehicleQuota" type="text" auto-complete="off" placeholder="企业配额"></el-input>
      </el-form-item>
      <el-form-item label="注册城市" prop="regCity" :rules="[{ 'required':true, 'message': '请输入注册城市','trigger': 'blur'}]">
        <el-input clearable size="mini" v-model="model.regCity" type="text" auto-complete="off" placeholder="注册城市"></el-input>
      </el-form-item>
      <el-form-item label="企业地址" prop="regAddress" :rules="[{ 'required':true, 'message': '请输入注册地址','trigger': 'blur'}]">
        <el-input clearable size="mini" v-model="model.regAddress" type="text" auto-complete="off" placeholder="注册地址"></el-input>
      </el-form-item>
      <el-form-item label="联系人" prop="principalCity" :rules="[{ 'required':true, 'message': '请输入联系人','trigger': 'blur'}]">
        <el-input clearable size="mini" v-model="model.principalCity" type="text" auto-complete="off" placeholder="联系人"></el-input>
      </el-form-item>
      <el-form-item label="联系电话" prop="principalPhone" :rules="[{ 'required':true, 'message': '请输入联系电话','trigger': 'blur'}, {pattern: /^1(3|4|5|6|7|8|9)\d{9}$/, message: '请填写有效的手机号码'}]">
        <el-input clearable size="mini" v-model="model.principalPhone" type="text" auto-complete="off" placeholder="联系电话"></el-input>
      </el-form-item>
      <el-form-item label="单车主题颜色" prop="principalCity" >
        <el-color-picker v-model="model.color"></el-color-picker>
      </el-form-item>
      <el-form-item></el-form-item>
      <div style="text-align: center; margin-bottom: 3px;">
        <el-button type="primary" @click="submitForm('iForm')">提交</el-button>
        <el-button @click="visible = false">取 消</el-button>
      </div>    
    </el-form>
  </el-dialog>
</template>

<script>
  export default {
    props:[],
    data () {
      return {
        visible: false, 
        model: {
          color: '#000'
        },
        rules: {},
      }
    },
    components: {},
    methods: {
      init(data){
        this.model   = data
        this.visible = true
        // 不用请求
        /*this.axios.post(process.env.API_HOST + `/punish/selectPunishDetail`, {id:id}).then(response => {
          const result = response.data
          if(result.code==200){
          }
        })*/
      },
      dialogClose(){
        this.visible = false
      },

      //提交回调
      doSubmit(){
        var data = {
          'enterpriseId' :     this.model.enterpriseId,
          'enterpriseName':    this.model.enterpriseName,
          'enterpriseAlias':   this.model.enterpriseAlias,
          'regCity' :          this.model.regCity,
          'regAddress' :       this.model.regAddress,
          'principalCity' :    this.model.principalCity,
          'principalPhone' :   this.model.principalPhone,
          'vehicleQuota' :     this.model.vehicleQuota,
          'color':             this.model.color,
        };

        this.axios.post(process.env.API_HOST + `/enterprise/updateEnterprise`, data).then(response=>{
            if(response.data.code==200){
              this.$message({
                type: 'success',
                message: '编辑成功!'
              });
              this.visible = false
            }
          })
          .catch(error=>{
            console.log(error);
          });
      },

      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.doSubmit()
          } else {
            return false;
          }
        });
      },

    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "../../../common/stylus/mixin.styl"
  .buttonAddWrap
    display inline-block
    margin-left 10px
</style>